using System;
using System.Linq;
using System.Text;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getTeamShipPosition : FunctionBase
    {
        private MarsExplorerEntities dbContext;
        public int TeamID { get; set; }
       
        public getTeamShipPosition(HttpContext context)
            : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            StringBuilder sb = new StringBuilder();
            try 
            { 
               
                Team t =(from x in dbContext.Teams where x.TeamID == TeamID select x).FirstOrDefault();
                switch (t.RouteID)
                {
                    case 1:
                        sb.Append(t.RouteID + ";" + t.Route.Name + ";2;7;13");
                        break;
                    case 20:
                        sb.Append(t.RouteID + ";" + t.Route.Name + ";5;11;18");
                        break;
                    default :
                        sb.Append(t.RouteID + ";" + t.Route.Name + ";" + t.Route.Next + ";" + t.Route.Prev + ";" + t.Route.SS);
                        break;
              	
                }
               
                return sb.ToString();
            }
            catch (Exception)
            {
                return "ERROR";
            }
        }

        public override void InitializeProperties()
        {
            try
            {
                TeamID = Convert.ToInt32(Parameters["teamid"]);
               
                dbContext = new MarsExplorerEntities();
            }
            catch (Exception e)
            {
                string message = "";
                #if DEBUG
                message += " : " + e.ToString();
                #endif
            }
        }
    }
}